#ifndef IOSERVICEPOOL_H
#define IOSERVICEPOOL_H

#include <boost/asio.hpp>
#include <vector>
#include "Singleton.h"

using namespace boost::asio;
using namespace std;

class IOServicePool : public Singleton<IOServicePool> {
    friend Singleton<IOServicePool>;

public:
    IOServicePool(const IOServicePool &) = delete;

    ~IOServicePool();

    IOServicePool &operator=(const IOServicePool &) = delete;

    io_context &GetIOContext();

    void stop();

private:
    explicit IOServicePool(unsigned int thread_nums = thread::hardware_concurrency());

    vector<io_context> _io_contexts;
    vector<unique_ptr<io_context::work> > _io_works;
    vector<thread> _threads;
    int _next_io_context;
};


#endif //IOSERVICEPOOL_H
